<?php

namespace app\adminapi\controller\v1\product;

use app\adminapi\controller\AuthController;
use app\adminapi\export\StoreProductLabelExport;
use app\services\product\product\StoreProductLabelServices;
use think\facade\App;

class StoreProductLabels extends AuthController
{
    protected $service;

    public function __construct(App $app, StoreProductLabelServices $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }

    public function index()
    {
        $where = $this->request->getMore([
            ['label_name', ''],
            ['limit', 15]
        ]);
        $data = $this->service->getList($where);
        return app('json')->success($data);
    }

    public function export()
    {
        $where = $this->request->getMore([
            ['label_name', ''],
            ['limit', 15]
        ]);

        return app()->make(StoreProductLabelExport::class)->export($where);
    }

    public function all()
    {
        $list = $this->service->all();
        return app('json')->success($list);
    }


    public function save($id)
    {
        $data = $this->request->postMore([
            ['label_name', ''],//
            ['sort_order', 0],//
            ['is_displayed_on_home', 0]
        ]);
        $this->service->save((int)$id, $data);
        return app('json')->success(100000);
    }

    public function delete($id)
    {
        $this->service->del($id);
        return app('json')->success(100002);
    }
}